#include "SetDefault.h"
//---------------------------------------------------------------------------
bool SetDefault::FirstRun()
{
        bool result = false;
        String MainPath,MainFileName,XMLFileName;
        LoadXMLFile lXMLf;

        MainPath = ExtractFilePath(Application->ExeName);
        MainFileName = ExtractFileName(Application->ExeName);
        XMLFileName = MainPath + "Setting.xml";
        if(FileExists(XMLFileName) == false)
        {
                result = true;
                Setting defaultSetting;
                defaultSetting.LeftPath = "C:";
                defaultSetting.RightPath = "C:";
                defaultSetting.DefaultLanguage = "English";

                lXMLf.SetSetting("setting.xml",defaultSetting);
        }


        String AutoString;
        TRegistry *MyReg = new TRegistry();
        MyReg->RootKey = HKEY_LOCAL_MACHINE;

        //MyReg->OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\EventHandlers\\PlayMusicFilesOnArrival",false);

        MyReg->OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\Handlers\\ConvertFile",true);

        AutoString = MyReg->ReadString("Action");

        if(AutoString == "")
        {

                //MyReg->CreateKey("");
                //MyReg->OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\Handlers\\ConvertFile",false);

                result = true;
                MyReg->WriteString("Action","Use File Convert");
                MyReg->WriteString("Provider","Convert");
                MyReg->WriteString("InvokeProgID","Convert.AutoPlayHandler");
                MyReg->WriteString("InvokeVerb","Open");
                MyReg->WriteString("DefaultIcon",Application->ExeName + ",0");

                MyReg->CloseKey();
                MyReg->OpenKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\AutoplayHandlers\\EventHandlers\\PlayMusicFilesOnArrival",false);
                MyReg->WriteString("ConvertFile","");

                MyReg->CloseKey();
                MyReg->CreateKey("SOFTWARE\\Classes\\Convert.AutoPlayHandler");
                MyReg->CreateKey("SOFTWARE\\Classes\\Convert.AutoPlayHandler\\shell");
                MyReg->CreateKey("SOFTWARE\\Classes\\Convert.AutoPlayHandler\\shell\\Open");
                MyReg->OpenKey("SOFTWARE\\Classes\\Convert.AutoPlayHandler\\shell\\Open",false);
                MyReg->WriteString("","Converting");

                MyReg->CreateKey("command");
				MyReg->OpenKey("command",false);
				MyReg->WriteString("","\"" + Application->ExeName + "\" \"%1\"");
        }
/*
        if((MyReg->ReadString("OS") == "Windows_NT") && (PathSettring.Pos(MainPath) <= 0))
        {
                result = true;
                PathSettring = MainPath + ";" + PathSettring;
                MyReg->OpenKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment",false);
                MyReg->WriteExpandString("Path",PathSettring);
                MyReg->OpenKey("SYSTEM\\ControlSet001\\Control\\Session Manager\\Environment",false);
                MyReg->WriteExpandString("Path",PathSettring);
                MyReg->OpenKey("SYSTEM\\ControlSet002\\Control\\Session Manager\\Environment",false);
                MyReg->WriteExpandString("Path",PathSettring);
        }
*/

		MyReg->RootKey = HKEY_CLASSES_ROOT;
		MyReg->CreateKey(".dvs");
		MyReg->OpenKey(".dvs",false);
		MyReg->WriteString("","dvsfile");
        MyReg->CloseKey();

		MyReg->CreateKey("dvsfile");
		MyReg->OpenKey("dvsfile",false);

		MyReg->CreateKey("DefaultIcon");
		MyReg->OpenKey("DefaultIcon",false);
		MyReg->WriteString("",MainPath + "Program.ico");
        MyReg->CloseKey();

		MyReg->OpenKey("dvsfile",false);
		MyReg->CreateKey("shell");
		MyReg->OpenKey("shell",false);
		MyReg->CreateKey("open");
		MyReg->OpenKey("open",false);
		MyReg->WriteString("","Open");
		MyReg->CreateKey("command");
		MyReg->OpenKey("command",false);
		MyReg->WriteString("",Application->ExeName + " %1");

		delete MyReg;

        if(HasLanguage() == false)
        {
        }

        return result;
}
//---------------------------------------------------------------------------
bool SetDefault::HasLanguage()
{
        bool result = true;
        String MainPath,LanguagePath;

        MainPath = ExtractFilePath(Application->ExeName);
        LanguagePath = MainPath + "\\Language";
        if(DirectoryExists(LanguagePath) == false)
        {
                result = false;
                CreateDir(LanguagePath);
        }
        else if(FileExists(LanguagePath + "\\English.xml") == false)
        {
                result = false;
        }

        return result;
}
//---------------------------------------------------------------------------
void SetDefault::SetDefaultXML(LoadXMLFile *lXMLf)
{
        MainMsgMenu defaultMainMenu;

        defaultMainMenu.File = "|File";
        defaultMainMenu.Open = "|Open";
        defaultMainMenu.SaveAs = "|Save As";
        defaultMainMenu.Exit = "|Exit";
        defaultMainMenu.Edit = "|Edit";
        defaultMainMenu.Copy = "|Copy";
        defaultMainMenu.Delete = "|Delete";
        defaultMainMenu.Paste = "|Paste";
        defaultMainMenu.Convert = "C|onvert";
        defaultMainMenu.Play = "|Play";
        defaultMainMenu.Help = "Help";
        defaultMainMenu.ConvertHelp = "|ConvertHelp";
        defaultMainMenu.About = "|About";
        defaultMainMenu.Language = "|Language";

        defaultMainMenu.Name = "Name";
        defaultMainMenu.Size = "Size";
        defaultMainMenu.Date = "Date";


        defaultMainMenu.MsgDelete = "Are you sure you want to delete file";
        defaultMainMenu.MsgOvercast = "Are you overcast the convert file";
        defaultMainMenu.MsgReplace = "Would you like to replace the existing file";
        defaultMainMenu.MsgOpen = "Please select open file path";
        defaultMainMenu.MsgSaveAs = "Please select save file path";
        defaultMainMenu.MsgFinish = "Convert finish";
        defaultMainMenu.MsgWelcome = "Welcome first use";
        defaultMainMenu.MsgFileFolder = "Failed to get pointer to shells task allocator";
        defaultMainMenu.MsgError = "Convert Error";
        defaultMainMenu.MsgAddPen = "You insert the record pen";
        defaultMainMenu.MsgRremove = "You remove the driver";
        defaultMainMenu.MsgDll = "Cannot found Dll";
        defaultMainMenu.MsgTitel = "Convert";
        defaultMainMenu.MsgUse = "Convert";
        defaultMainMenu.MsgAutoRun = "Use File Convert";

        lXMLf->SetMessage(&defaultMainMenu);
}
//---------------------------------------------------------------------------

